home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / NeoIntroTCL3.0 folder / TCL / NeoDemo / Source / CNDFilePicture.cp < prev    next >
Encoding:
Text File  |  1994-08-01  |  3.0 KB  |  131 lines  |  [TEXT/KAHL]

  1. /****
  2.  * CNDFilePicture.c
  3.  *
  4.  *  Copyright © 1992 NeoLogic Systems.  All rights reserved.
  5.  *
  6.  ****/
  7.  
  8. #include "NeoTypes.h"
  9. #include "CNDFilePicture.h"
  10. #include <commands.h>
  11. #include <CPaneBorder.h>
  12. #include "CNDImage.h"
  13. #include "CNeoDialogText.h"
  14.  
  15. extern CBureaucrat *gGopher;
  16.  
  17. void    CNDFilePicture::INDFilePicture(
  18.     CView            *anEnclosure,
  19.     CBureaucrat        *aSupervisor,
  20.     short            aWidth,
  21.     short            aHeight,
  22.     short            aHEncl,
  23.     short            aVEncl,
  24.     SizingOption    aHSizing,
  25.     SizingOption    aVSizing)
  26. {
  27.     inherited::IPicture(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl,aVEncl,
  28.                             aHSizing, aVSizing);
  29.  
  30.     canBeGopher = TRUE;
  31.     fImage = nil;
  32. }
  33.  
  34. CNDFilePicture::~CNDFilePicture(void)
  35. {
  36.     setImage(nil);
  37. }
  38.  
  39. void CNDFilePicture::setImage(CNDImage *aImage)
  40. {
  41.     if (fImage != aImage) {
  42.         if (fImage)
  43.             fImage->unrefer();
  44.  
  45.         if (aImage)
  46.             aImage->referTo();
  47.  
  48.         fImage = aImage;
  49.     }
  50. }
  51.  
  52. Boolean CNDFilePicture::BecomeGopher(Boolean fBecoming)
  53. {
  54.     short    inset;
  55.     if(inherited::BecomeGopher(fBecoming))
  56.     {
  57.         Rect r;
  58.  
  59.         if(fBecoming)
  60.             itsBorder->SetPattern(&qd.black);
  61.         else
  62.             itsBorder->SetPattern(&qd.white);
  63.         RefreshBorder();
  64.         return TRUE;
  65.     }
  66.     else
  67.         return FALSE;
  68. }
  69.  
  70. void    CNDFilePicture::Draw(Rect *area)
  71. {
  72.     Boolean        imageBusy;
  73.     float        tempHor;
  74.     float        tempVer;
  75.     float        pictHor;
  76.     float        pictVer;
  77.     Rect        tempRect;
  78.     Rect        pictRect;
  79.     Rect        frameRect;
  80.     PicHandle    pict;
  81.  
  82.     LongToQDRect(&aperture, &tempRect);
  83.     InsetRect(&tempRect, 4, 4);                                /* leave room for border */
  84.     frameRect = tempRect;
  85.  
  86.     if (fImage)
  87.         pict = (PicHandle)fImage->getBlob();
  88.     else
  89.         pict = nil;
  90.  
  91.     if (pict) {
  92.         imageBusy = fImage->isBlobBusy();
  93.         fImage->setBlobBusy(TRUE);                            /* so the image can't be purged */
  94.         tempHor = tempRect.right - tempRect.left;
  95.         tempVer = tempRect.bottom - tempRect.top;
  96.         pictRect = (**pict).picFrame;
  97.         pictHor = pictRect.right - pictRect.left;
  98.         pictVer = pictRect.bottom - pictRect.top;
  99.         EraseRect(&tempRect);
  100.         if ((tempHor > pictHor) && (tempVer > pictVer)) {   /* picture is smaller than frame */
  101.             tempRect.left += (tempHor - pictHor) / 2;
  102.             tempRect.right = tempRect.left + pictHor;
  103.             tempRect.top += (tempVer - pictVer) / 2;
  104.             tempRect.bottom = tempRect.top + pictVer;
  105.         }
  106.         else                                                /* at least one picture dimension is larger than frame */
  107.         if ((pictVer / tempVer) > (pictHor / tempHor)) {    /* proportionally longer in vertical dimension */
  108.             pictHor *= tempVer / pictVer;                    /* scale horizontal to keep proportion */
  109.             if (tempHor > pictHor) {
  110.                 tempRect.left += (tempHor - pictHor) / 2;
  111.                 tempRect.right = tempRect.left + pictHor;
  112.             }
  113.         }
  114.         else {                                                /* proportionally longer in horizontal dimension */
  115.             pictVer *= tempHor / pictHor;                    /* scale vertical to keep proportion */
  116.             if (tempVer > pictVer) {
  117.                 tempRect.top += (tempVer - pictVer) / 2;
  118.                 tempRect.bottom += tempRect.top + pictVer;
  119.             }
  120.         }
  121.  
  122.         fImage->draw(&tempRect);
  123.         fImage->setBlobBusy(imageBusy);                        /* reset purgability of image */
  124.     }
  125.     else
  126.         EraseRect(&tempRect);
  127.  
  128.     InsetRect(&frameRect, -1, -1);                            /* back out for border */
  129.     FrameRect(&frameRect);
  130. }
  131.